<?php

/** 
 * 
 * @author      knight
 * @date        17/5/22
 */
class Last extends CI_Controller
{

    function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function index($num = 0, $offset = 20)
    {
        $data = array();
        $where = array(
            'type' => '3'
        ) // type:3,客牛招聘;
;
        $data['title'] = '微信活动案例-微信招生真实案例-微信免费活动案例-微信砍价案例-商家岛活动案例-微信招生怎么做活动案例';
        
        $sql = "select activity_id,sum(view_count) view_count from `kn_statistics` where view_count>'50' group by activity_id order by activity_id desc ";
        $stats = $this->common_model->get_all_by_sql($sql);
        
        $act_ids = array();
        foreach ($stats as $vo) {
            $act_ids[] = $vo['activity_id'];
        }
        $data['lists'] = $this->common_model->getlists_by_ids($act_ids, 'activities', 'id,user_id,start_time,title');
        // 通过活动id查找用户信息
        $users = array();
        foreach ($data['lists'] as $vo) {
            if (! in_array($vo['user_id'], $users)) {
                $users[] = $vo['user_id'];
            }
        }
        $data['users'] = $this->common_model->getlists_by_ids($users, 'users', 'id,organization,industry,province,city');
        
        if (isset($data['lists'][$offset])) {
            $num ++;
            $data['pager'] = "<a class='more fl font14 c64' href='/cases/{($num)}'>下&nbsp;一&nbsp;页</a>";
        } else {
            $data['pager'] = "<a class='more fl font14 c64' >已经是最后一页了</a>";
        }
        
        $this->load->view('last/index', $data);
    }

    function detail($aid = 0)
    {
        $aid = base64_decode(str_replace('-', '=', $aid));
        
        // 活动本身内容显示
        $data['act'] = $this->common_model->getone_byid($aid, 'activities');
        // dump($data);
        if ($data['act']) {
            $key = '';
            $key = explode('_', $data['act']['key']);
            $key = $key[0];
            switch ($key) {
                case 'kanjia':
                    $title = '微信砍价活动';
                    $key = '微信砍价,微信砍价活动,客牛砍价,微信招生砍价,商家岛砍价,商家岛砍价活动';
                    break;
                case 'qmjz':
                    $title = '微信集赞活动';
                    $key = '微信集赞,全民集赞,微信集赞活动,客牛集赞,商家岛集赞,商家岛集赞活动';
                    break;
                case 'comeon':
                    $title = '微信加油活动';
                    $key = '微信加油,超级加油,微信超级加油,客牛加油,商家岛加油,商家岛加油活动';
                    break;
                case 'qiangqian':
                    $title = '微信抢钱活动';
                    $key = '微信抢钱活动,客牛抢钱活动,微信抢钱';
                    break;
                case 'kanjia51':
                    $title = '微信51砍价活动';
                    $key = '微信砍价,微信砍价活动,客牛砍价,商家岛砍价,商家岛砍价活动';
                    break;
            }
            $data['key'] = $key;
            $data['title'] = $title;
            if ($data['act']['domain']) {
                $data['src'] = 'http://act.keniu8.cn/act/' . $data['act']['id'] . '?fromback';
            } else {
                $data['src'] = 'http://act.keniu8.cn/act/' . $data['act']['id'] . '?fromback';
            }
            
            $this->load->view('last/detail', $data);
        } else {
            show_404();
        }
    }

    function realy_act($aid)
    {
        $aid = base64_decode(str_replace('-', '=', $aid));
        echo $aid ? @file_get_contents('http://wx.keniu.site/link/index/' . $aid) : '';
    }
}
